home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3g / regexpr.z / regexpr
Encoding:
Text File  |  1998-10-20  |  13.3 KB  |  198 lines

  1.  
  2.  
  3.  
  4. rrrreeeeggggeeeexxxxpppprrrr((((3333GGGG))))                                                        rrrreeeeggggeeeexxxxpppprrrr((((3333GGGG))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _rrrr_eeee_gggg_eeee_xxxx_pppp_rrrr: _cccc_oooo_mmmm_pppp_iiii_llll_eeee, _ssss_tttt_eeee_pppp, _aaaa_dddd_vvvv_aaaa_nnnn_cccc_eeee - regular expression compile and match
  10.      routines
  11.  
  12. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.      _cccc_cccc [_f_l_a_g ...] _f_i_l_e ...  _----_llll_gggg_eeee_nnnn [_l_i_b_r_a_r_y ...]
  14.  
  15.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_rrrr_eeee_gggg_eeee_xxxx_pppp_rrrr_...._hhhh_>>>>
  16.  
  17.      _cccc_hhhh_aaaa_rrrr _****_cccc_oooo_mmmm_pppp_iiii_llll_eeee _((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_i_n_s_t_r_i_n_g_,,,, _cccc_hhhh_aaaa_rrrr _****_e_x_p_b_u_f_,,,, _cccc_hhhh_aaaa_rrrr _****_e_n_d_b_u_f_))))_;;;;
  18.  
  19.      _iiii_nnnn_tttt _ssss_tttt_eeee_pppp _((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_s_t_r_i_n_g_,,,, _cccc_hhhh_aaaa_rrrr _****_e_x_p_b_u_f_))))_;;;;
  20.  
  21.      _iiii_nnnn_tttt _aaaa_dddd_vvvv_aaaa_nnnn_cccc_eeee _((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_s_t_r_i_n_g_,,,, _cccc_hhhh_aaaa_rrrr _****_e_x_p_b_u_f_))))_;;;;
  22.  
  23.      _eeee_xxxx_tttt_eeee_rrrr_nnnn _cccc_hhhh_aaaa_rrrr _****_llll_oooo_cccc_1111_,,,, _****_llll_oooo_cccc_2222_,,,, _****_llll_oooo_cccc_ssss_;;;;
  24.  
  25.      _eeee_xxxx_tttt_eeee_rrrr_nnnn _iiii_nnnn_tttt _nnnn_bbbb_rrrr_aaaa_,,,, _rrrr_eeee_gggg_eeee_rrrr_rrrr_nnnn_oooo_,,,, _rrrr_eeee_gggg_llll_eeee_nnnn_gggg_tttt_hhhh_;;;;
  26.  
  27.      _eeee_xxxx_tttt_eeee_rrrr_nnnn _cccc_hhhh_aaaa_rrrr _****_bbbb_rrrr_aaaa_ssss_llll_iiii_ssss_tttt_[[[[_]]]]_,,,, _****_bbbb_rrrr_aaaa_eeee_llll_iiii_ssss_tttt_[[[[_]]]]_;;;;
  28.  
  29. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  30.      These routines are used to compile regular expressions and match the
  31.      compiled expressions against lines.  The regular expressions compiled are
  32.      in the form used by _eeee_dddd.
  33.  
  34.      The syntax of the _cccc_oooo_mmmm_pppp_iiii_llll_eeee routine is as follows:
  35.  
  36.           _cccc_oooo_mmmm_pppp_iiii_llll_eeee _((((_iiii_nnnn_ssss_tttt_rrrr_iiii_nnnn_gggg_,,,, _eeee_xxxx_pppp_bbbb_uuuu_ffff_,,,, _eeee_nnnn_dddd_bbbb_uuuu_ffff_))))
  37.  
  38.      The parameter _i_n_s_t_r_i_n_g is a null-terminated string representing the
  39.      regular expression.
  40.  
  41.      The parameter _e_x_p_b_u_f points to the place where the compiled regular
  42.      expression is to be placed.  If _e_x_p_b_u_f is _NNNN_UUUU_LLLL_LLLL, _cccc_oooo_mmmm_pppp_iiii_llll_eeee uses _mmmm_aaaa_llll_llll_oooo_cccc to
  43.      allocate the space for the compiled regular expression.  If an error
  44.      occurs, this space is freed.  It is the user's responsibility to free
  45.      unneeded space after the compiled regular expression is no longer needed.
  46.  
  47.      The parameter _e_n_d_b_u_f is one more than the highest address where the
  48.      compiled regular expression may be placed.  This argument is ignored if
  49.      _e_x_p_b_u_f is _NNNN_UUUU_LLLL_LLLL.  If the compiled expression cannot fit in (_e_n_d_b_u_f-_e_x_p_b_u_f)
  50.      bytes, _cccc_oooo_mmmm_pppp_iiii_llll_eeee returns _NNNN_UUUU_LLLL_LLLL and _rrrr_eeee_gggg_eeee_rrrr_rrrr_nnnn_oooo (see below) is set to 50.
  51.  
  52.      If _cccc_oooo_mmmm_pppp_iiii_llll_eeee succeeds, it returns a non-_NNNN_UUUU_LLLL_LLLL pointer whose value depends on
  53.      _e_x_p_b_u_f.  If _e_x_p_b_u_f is non-_NNNN_UUUU_LLLL_LLLL, _cccc_oooo_mmmm_pppp_iiii_llll_eeee returns a pointer to the byte
  54.      after the last byte in the compiled regular expression.  The length of
  55.      the compiled regular expression is stored in _rrrr_eeee_gggg_llll_eeee_nnnn_gggg_tttt_hhhh.  Otherwise,
  56.      _cccc_oooo_mmmm_pppp_iiii_llll_eeee returns a pointer to the space allocated by _mmmm_aaaa_llll_llll_oooo_cccc.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. rrrreeeeggggeeeexxxxpppprrrr((((3333GGGG))))                                                        rrrreeeeggggeeeexxxxpppprrrr((((3333GGGG))))
  71.  
  72.  
  73.  
  74.      If an error is detected when compiling the regular expression, a _NNNN_UUUU_LLLL_LLLL
  75.      pointer is returned from _cccc_oooo_mmmm_pppp_iiii_llll_eeee and _rrrr_eeee_gggg_eeee_rrrr_rrrr_nnnn_oooo is set to one of the non-
  76.      zero error numbers indicated below:
  77.  
  78.                    ERROR                  MEANING
  79.                    _____________________________________________
  80.                     11     Range endpoint too large.
  81.                     16     Bad number.
  82.                     25     ``_\\\\digit'' out of range.
  83.                     36     Illegal or missing delimiter.
  84.                     41     No remembered search string.
  85.                     42     _\\\\_((((_~~~~_\\\\_)))) imbalance.
  86.                     43     Too many _\\\\_((((.
  87.                     44     More than 2 numbers given in _\\\\_{{{{_~~~~_\\\\_}}}}.
  88.                     45     _}}}} expected after _\\\\.
  89.                     46     First number exceeds second in _\\\\_{{{{_~~~~_\\\\_}}}}.
  90.                     49     _[[[[ _]]]] imbalance.
  91.                     50     Regular expression overflow.
  92.  
  93.      The call to _ssss_tttt_eeee_pppp is as follows:
  94.  
  95.           _ssss_tttt_eeee_pppp _((((_ssss_tttt_rrrr_iiii_nnnn_gggg_,,,, _eeee_xxxx_pppp_bbbb_uuuu_ffff_))))
  96.  
  97.      The first parameter to _ssss_tttt_eeee_pppp is a pointer to a string of characters to be
  98.      checked for a match.  This string should be null-terminated.
  99.  
  100.      The parameter _e_x_p_b_u_f is the compiled regular expression obtained by a
  101.      call of the function _cccc_oooo_mmmm_pppp_iiii_llll_eeee.
  102.  
  103.      The function _ssss_tttt_eeee_pppp returns non-zero if the given string matches the
  104.      regular expression, and zero if the expressions do not match.  If there
  105.      is a match, two external character pointers are set as a side effect to
  106.      the call to _ssss_tttt_eeee_pppp.  The variable set in _ssss_tttt_eeee_pppp is _llll_oooo_cccc_1111.  _llll_oooo_cccc_1111 is a pointer
  107.      to the first character that matched the regular expression.  The variable
  108.      _llll_oooo_cccc_2222 points to the character after the last character that matches the
  109.      regular expression.  Thus if the regular expression matches the entire
  110.      line, _llll_oooo_cccc_1111 points to the first character of _s_t_r_i_n_g and _llll_oooo_cccc_2222 points to the
  111.      null at the end of _s_t_r_i_n_g.
  112.  
  113.      The purpose of _ssss_tttt_eeee_pppp is to step through the _s_t_r_i_n_g argument until a match
  114.      is found or until the end of _s_t_r_i_n_g is reached.  If the regular
  115.      expression begins with _^^^^, _ssss_tttt_eeee_pppp tries to match the regular expression at
  116.      the beginning of the string only.
  117.  
  118.      The function _aaaa_dddd_vvvv_aaaa_nnnn_cccc_eeee has the same arguments and side effects as _ssss_tttt_eeee_pppp, but
  119.      it always restricts matches to the beginning of the string.
  120.  
  121.      If one is looking for successive matches in the same string of
  122.      characters, _llll_oooo_cccc_ssss should be set equal to _llll_oooo_cccc_2222, and _ssss_tttt_eeee_pppp should be called
  123.      with _s_t_r_i_n_g equal to _llll_oooo_cccc_2222.  _llll_oooo_cccc_ssss is used by commands like _eeee_dddd and _ssss_eeee_dddd so
  124.      that global substitutions like _ssss_////_yyyy_****_////_////_gggg do not loop forever, and is _NNNN_UUUU_LLLL_LLLL
  125.      by default.
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. rrrreeeeggggeeeexxxxpppprrrr((((3333GGGG))))                                                        rrrreeeeggggeeeexxxxpppprrrr((((3333GGGG))))
  137.  
  138.  
  139.  
  140.      The external variable _nnnn_bbbb_rrrr_aaaa is used to determine the number of
  141.      subexpressions in the compiled regular expression.  _bbbb_rrrr_aaaa_ssss_llll_iiii_ssss_tttt and _bbbb_rrrr_aaaa_eeee_llll_iiii_ssss_tttt
  142.      are arrays of character pointers that point to the start and end of the
  143.      _nnnn_bbbb_rrrr_aaaa subexpressions in the matched string.  For example, after calling
  144.      _ssss_tttt_eeee_pppp or _aaaa_dddd_vvvv_aaaa_nnnn_cccc_eeee with string _ssss_aaaa_bbbb_cccc_dddd_eeee_ffff_gggg and regular expression _\\\\_((((_aaaa_bbbb_cccc_dddd_eeee_ffff_\\\\_)))),
  145.      _bbbb_rrrr_aaaa_ssss_llll_iiii_ssss_tttt_[[[[_0000_]]]] will point at _aaaa and _bbbb_rrrr_aaaa_eeee_llll_iiii_ssss_tttt_[[[[_0000_]]]] will point at _gggg.  These
  146.      arrays are used by commands like _eeee_dddd and _ssss_eeee_dddd for substitute replacement
  147.      patterns that contain the _\\\\_n notation for subexpressions.
  148.  
  149.      Note that it isn't necessary to use the external variables _rrrr_eeee_gggg_eeee_rrrr_rrrr_nnnn_oooo,
  150.      _nnnn_bbbb_rrrr_aaaa, _llll_oooo_cccc_1111, _llll_oooo_cccc_2222 _llll_oooo_cccc_ssss, _bbbb_rrrr_aaaa_eeee_llll_iiii_ssss_tttt, and _bbbb_rrrr_aaaa_ssss_llll_iiii_ssss_tttt if one is only checking
  151.      whether or not a string matches a regular expression.
  152.  
  153. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  154.      The following is similar to the regular expression code from _gggg_rrrr_eeee_pppp:
  155.  
  156.           _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_rrrr_eeee_gggg_eeee_xxxx_pppp_rrrr_...._hhhh_>>>>
  157.           _.... _.... _....
  158.           _iiii_ffff_((((_cccc_oooo_mmmm_pppp_iiii_llll_eeee_((((_****_aaaa_rrrr_gggg_vvvv_,,,, _((((_cccc_hhhh_aaaa_rrrr _****_))))_0000_,,,, _((((_cccc_hhhh_aaaa_rrrr _****_))))_0000_)))) _====_==== _((((_cccc_hhhh_aaaa_rrrr _****_))))_0000_))))
  159.              _rrrr_eeee_gggg_eeee_rrrr_rrrr_((((_rrrr_eeee_gggg_eeee_rrrr_rrrr_nnnn_oooo_))))_;;;;
  160.           _.... _.... _....
  161.           _iiii_ffff _((((_ssss_tttt_eeee_pppp_((((_llll_iiii_nnnn_eeee_bbbb_uuuu_ffff_,,,, _eeee_xxxx_pppp_bbbb_uuuu_ffff_))))_))))
  162.              _ssss_uuuu_cccc_cccc_eeee_eeee_dddd_((((_))))_;;;;
  163.  
  164. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  165.      _eeee_dddd(1), _gggg_rrrr_eeee_pppp(1), _ssss_eeee_dddd(1), _rrrr_eeee_gggg_eeee_xxxx_pppp(5)
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.                                                                         PPPPaaaaggggeeee 3333
  194.  
  195.  
  196.  
  197.